//
//  KLPageControlView.m
//  Meboo
//
//  Created by kyo on 2023/10/8.
//

#import "KLPageControlView.h"

@interface KLPageControlView ()

@property (nonatomic, strong) NSMutableArray *viewArr;

@end

@implementation KLPageControlView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Public Metohd
- (void)setIndex:(NSInteger)index {
    _index = index;
    for (int i = 0; i < 4; i++) {
        UIView *view = self.viewArr[i];
        if (i == index) {
            view.backgroundColor = HEXS(@"B92176");
        } else {
            view.backgroundColor = HEXS(@"D9D9D9");
        }
    }
}

#pragma mark - UI
- (void)setupUI {
    self.backgroundColor = UIColor.clearColor;
    for (int i = 0; i < 4; i++) {
        UIView *pageView = [UIView new];
        pageView.backgroundColor = HEXS(@"D9D9D9");
        if (i == 0) {
            pageView.backgroundColor = HEXS(@"B92176");
        }
        pageView.layer.cornerRadius = MBHeightScale(1.5);
        [self addSubview:pageView];
        [pageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(MBWidthScale(18));
            make.top.bottom.equalTo(self);
            make.left.mas_equalTo(MBWidthScale(28)*i);
        }];
        [self.viewArr addObject:pageView];
    }
}

#pragma mark - Setter && Getter
- (NSMutableArray *)viewArr {
    if (!_viewArr) {
        _viewArr = [NSMutableArray array];
    }
    return _viewArr;
}

@end
